<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="<?php echo site_url('js/jquery.js')?>"></script>
<script type="text/javascript" src="<?php echo site_url('js/checkfrm.js')?>"></script>
<title>抽奖管理后台</title>

<style>
body{background:#F4F4FF; font-size:14px; margin:auto}
.divScroll{     OVERFLOW:auto;
        scrollbar-face-color: #FFFFFF;
        scrollbar-shadow-color: #D2E5F4;
        scrollbar-highlight-color: #D2E5F4;
        scrollbar-3dlight-color: #FFFFFF;
        scrollbar-darkshadow-color: #FFFFFF;
        scrollbar-track-color: #FFFFFF; 
      scrollbar-arrow-color: #D2E5F4;
	  }
</style>
<script type="text/javascript">
	var product = new Array;
	var productnum = new Array;
	<?php
		foreach( $product as $pk => $pv ){
			$tmp[]=implode(',',$pv);
			$tmp3[$pv['id']][] = $pv;
	?>
	productnum[<?=$pv['id']?>]=<?=count($product[$pk])?>;
	<?php
		} 
	?>
	product = ['<?php echo implode('\',\'',$tmp);?>'];
	
	var stock = new Array;
	<?php
		foreach($stock as $sk => $sv){
			$tmp2 = array();
			foreach($sv as $svk => $svv){
				$tmp2[] = implode(',',$svv);
			}
			$tmp3[] =  implode('\',\'',$tmp2);
	?>
	stock[<?=$sk?>] = ['<?php echo implode('\',\'',$tmp3);?>'];
	
	<?php
		unset($tmp3);
	}		
	?>
	
	//alert(stock[17].pop());
	
	//创建select	
	function createselect(){
		var str = '<select name="product[]" id="productid">';
		for(var i=0;i<product.length;i++){
			ch = new Array;
 			ch = product[i].split(",");
			var len = stock[ch[0]].length;
			if(len > 0){
				if(i == 0){
					str+='<option value="'+ch[0]+'" selected="selected">'+ch[1]+'</option>';
				}else{
					str+='<option value="'+ch[0]+'">'+ch[1]+'</option>';
				}
				
			}
			
		}
		str+='</select>';
		return str;
	}
	 
	 
	 
	function openwin(url)
	{
		window.location=''+url+'';
	}

	function submitfrm()
	{
		var price = $('#price').val();
		var singleprice = $('#singleprice').val();
		var maxnumber = $('#maxnumber').val();
		var infos = $('#infos').val();
		var beginDate = $('#beginDate').val();
		var endDate = $('#endDate').val();
		
		if(infos == '')
		{
			alert('活动名称不能为空');
			return false;
		}
		
		if(!checkprice(price))
		{
			alert('请正确填写:中奖金额');
			return false;
		}
		if(!checkprice(singleprice))
		{
			alert('请正确填写:单位金额');
			return false;
		}
		if(!checkint(maxnumber))
		{
			alert('请正确填写-最大可选数字');
			return false;
		}

		document.addreward.submit();
	}
	
	function addstock(){

		var id = $("#productid").val();
			
		var items = $("select[name=product[]] option[selected]").text(); 
		$("#productv").append('<li>'+items+'<a href="">删除</a></li>');
		stock[id].pop();
		var str = createselect();
		$("#stock").html(str);
	
	}
$(function(){
	var str = createselect();
	$("#stock").html(str);
});
</script>
</head>

<body topmargin="0">
<table width="1000px" border="0" cellpadding="0" bgcolor="#F4F4FF">
  <tr>
    <td width="235" height="37">&nbsp;</td>
    <td width="759">&nbsp;</td>
  </tr>
  <tr>
    <td height="30">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="485" align="center" valign="top">
<?php require_once 'left.php';?>
    </td>
    <td valign="top" align="center">
	
<form action="addreward" method="post" enctype="multipart/form-data" name="addreward">
<table width="100%" border="0" >

    <td width="15%" height="31">添加活动:</td>
    <td width="84%"></td>
    <td width="1%"></td>
  </tr>
  <tr>
    <td width="15%" height="31" align="left">活动信息:</td>
    <td width="84%" align="left"><label>
      <input  name="infos" value="<?php echo set_value('infos'); ?>" id="infos"/>
    (*)</label></td>
  </tr>
   <tr>
    <td width="15%" height="31" align="left">活动图片:</td>
    <td width="84%" align="left">
      <input type="file" name="rewardpic" id="fileField" />       </td>
  </tr>
     <tr>
    <td width="15%" height="31" align="left">展示类型:</td>
    <td width="84%" align="left">
   
      <select name="showtype" id="select">
      <option value="1">文字</option>
      <option value="2">图片</option>
      </select>            </td>
  </tr>
  <tr>
    <td height="36" align="left">中奖金额:</td>
    <td align="left"><input  name="prices" value="<?php echo set_value('prices'); ?>" id="price"/>
    (*)</td>
  </tr>
  
  <tr>
    <td height="35" align="left">奖品:</td>
    <td align="left"><!--<a href="javascript:addproduct();">[+]</a>  -->
      <div id="stock" style="width:50px;"></div><input type="button" name="Submit2" value="添加" onclick="addstock();" />     </td>
  </tr>
   <!-- 
   <tr>
    <td height="35"></td>
    <td><input  name="products[]"/>
    (*)</td>
  </tr>
  -->
    <tr>
    <td height="35"></td>
    <td align="left">
	<div id="productv">

	
	</div>
    </td>
  </tr>
  
 
  <tr>
    <td height="39" align="left">单位金额:</td>
    <td align="left"><input  name="singleprice" value="<?php echo set_value('singleprice'); ?>" id="singleprice"/><font color='red'>(不带货币符号)</font></td>
  </tr>

      <tr>
    <td height="39" align="left">最大可选数字:</td>
    <td align="left"><input  name="maxnumber" value="" size="20" id="maxnumber"/><font color='red'>(大于1的整数)</font></td>
  </tr>

      <tr>
    <td height="39" align="left">状态：</td>
    <td align="left">
           <select name="enabled">
      	<option value="0">停止</option>
      	<option value="1">启动</option>
      	<option value="2">已结束</option>
      </select>    </td>
  </tr>
  <tr>
    <td height="44" align="left">备注：</td>
    <td align="left">
    <textarea name="content" cols="40" rows="10" id="textarea"></textarea>   </td>
  </tr>
    <tr>
    <td height="44">&nbsp;</td>
    <td>
      <input type="button" name="Submit" value="提交"  onclick="submitfrm();"/>
    </td>
  </tr>
</table>
</form>

    
    </td>
  </tr>
</table>
</body>
</html>
